package com.example.taximeter.service.impl;

import com.example.taximeter.bean.ReturnInfo;
import com.example.taximeter.bean.Search;
import com.example.taximeter.bean.TaximeterView;
import com.example.taximeter.mapper.SearchMapper;
import com.example.taximeter.service.SearchService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 查询
 */
@Service
public class SearchServiceImpl implements SearchService {

    private SearchMapper searchMapper;

    @Autowired
    public SearchServiceImpl(SearchMapper searchMapper){
        this.searchMapper = searchMapper;



    }

    @Override
    public ReturnInfo findSearchAll(Integer pageNum, Integer pageSize, Search search) {
        if(!pageNum.equals(0)||!pageSize.equals(0)){
            PageHelper.startPage(pageNum, pageSize);
        }
        Integer pagetotal = 0;
        Long total = 0L;
        List<Search> searches = searchMapper.findSearchAll(search);
        PageInfo<Search> pageInfo = new PageInfo<>(searches);
        if(searches.size()!=0){
            pagetotal = pageInfo.getPages();
            total = pageInfo.getTotal();
        }
        return ReturnInfo.info5(pagetotal,total,pageInfo.getList());
    }

    @Override
    public Integer findNewNum(String companyname) {
        if(companyname!=null&&!companyname.equals("")){
            return searchMapper.findNewNum(companyname);
        }else {
            return searchMapper.findNewNum2(companyname);
        }

    }

    @Override
    public Integer findNotNewNum(String companyname ) {
        if(companyname!=null&&!companyname.equals("")){
            return searchMapper.findNotNewNum(companyname);
        }else {
            return searchMapper.findNotNewNum2(companyname);
        }
    }
}
